package com.hmall.order.listen;

import com.hmall.common.client.item.client.ItemClient;
import com.hmall.common.pojo.RestoreDTO;
import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class ListenHandler {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private ItemClient itemClient;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("order.queue"),
            exchange = @Exchange(name = "order.delay", type = ExchangeTypes.DIRECT, delayed = "true"),
            key = {"dl"}
    ))
    public void checkOrderStatus(RestoreDTO restoreDTO) {
        log.info("接收到延时消息, 准备做对应处理: {}", restoreDTO);

        // TODO 完成订单超时处理; 注意: 跨服务; 跨数据库; 跨服务+数据库; 需要考虑分布式事务

    }
}
